package com.hmall.gateway.filter;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.List;

@Component
public class PrintAnyGatewayFilterFactory  extends AbstractGatewayFilterFactory<PrintAnyGatewayFilterFactory.Config> {
    @Override
    public GatewayFilter apply(Config config) {
        return new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                ////拦截请求
                //ServerHttpResponse response = exchange.getResponse();
                //放行
                System.out.println("路由过滤器 放行...."+config);
                return chain.filter(exchange);
            }
        };
    }
    //定义一个类(泛型)
    @Data
    static class Config{
        private String name;
        private String city;
        private String sex;
    }
    //返回对象（泛型）的属性名字
    @Override
    public List<String> shortcutFieldOrder(){
        return List.of("name","city","sex");
    }
    //获取类（泛型)的字节码
    //public PrintAnyGatewayFilterFactory(){
    //    super(Config.class);
    //}

    @Override
    public Class<Config> getConfigClass(){
        return Config.class;
    }


}
